package com.example.statemachine.guard;

import com.example.statemachine.ApplicationRequest;
import com.example.statemachine.StatesEvents;
import lombok.extern.slf4j.Slf4j;
import org.springframework.statemachine.StateContext;
import org.springframework.statemachine.guard.Guard;
import org.springframework.stereotype.Component;

/**
 * @Author: leizj
 * @Desc:
 */
@Slf4j
@Component
public class UploadGuard implements Guard<StatesEvents.State, StatesEvents.Event> {
    @Override
    public boolean evaluate(StateContext<StatesEvents.State, StatesEvents.Event> stateContext) {
        log.info("UploadGuard stateContext: {}", stateContext.getEvent());
        log.info("UploadGuard stateContext: {}", stateContext);
        ApplicationRequest applicationRequest = (ApplicationRequest) stateContext.getMessageHeader("APPLICATION_UPDATE_REQUEST_VO");
        log.info("UploadGuard applicationRequest: {}", applicationRequest);
        if ("false".equalsIgnoreCase(applicationRequest.getFlag())) {
            return false;
        }
        return true;
    }
}
